<%--
  Created by IntelliJ IDEA.
  User: oler
  Date: 15.09.14
  Time: 17:49
  To change this template use File | Settings | File Templates.
--%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

<%@ include file="../urls.jsp" %>

<c:set var="lang" value="${pageContext.response.locale}"/>
<spring:url var="viewEvents" value="/crm/events/view/${customerId}"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="${customersViewStyleUrl}"/>
    <link rel="stylesheet" type="text/css" href="${jQueryUIStyleUrl}">

    <script type="text/javascript" src="${jQueryUrl}"></script>
    <script type="text/javascript" src="${jQueryUIUrl}"></script>
    <script type="text/javascript" src="${jsHandlersUrl}"></script>
    <script type="text/javascript" src="${jsLocalChangeUrl}"></script>
    <script>
        saveIconUrl = '${saveIconUrl}';
        editIconUrl = '${editIconUrl}';
        deleteEventUrl = '${deleteEventUrl}';
        prepareUpdateEventUrl = '${prepareUpdateEventUrl}';
    </script>

    <title><spring:message code="title.eventsView"/></title>
</head>
<body>

<c:if test="${done eq true}">
    <script>
        $(function () {
            $("#success-done").dialog("open");
        });
    </script>
</c:if>

<%@ include file="../dialogs.jsp" %>
<%@ include file="../header.jsp" %>

<h1 style="text-align: center;"><spring:message code="events.Caption"/></h1>

<br/><br/>
<button onclick="window.location.href='${customersUrl}/1'">Back to customers</button>
<table border="0">
    <tr>
        <td class="eventCaptCell" id="ce1"><spring:message
                code="custview.EventType"/></td>
        <td class="eventCaptCell" id="ce2"><spring:message
                code="custview.EventDescription"/></td>
        <td class="eventCaptCell" id="ce3"><spring:message
                code="custview.EventDate"/></td>
        <td class="eventCaptCell" id="ce4"><spring:message
                code="custview.EventStatus"/></td>
        <td class="eventCaptCell" id="ce5"><spring:message
                code="custview.EventBinding"/></td>
        <td class="eventCaptCell" id="ce6" style="display: table-cell"></td>
        <c:if test="${displayManagerContext}">
            <td class="eventCaptCell" id="ce7"></td>
        </c:if>
    </tr>
</table>

<c:forEach var="event" items="${customerEvents}">

    <form:form commandName="event" action="${updateEventUrl}" id="editEventForm${event.id}">
        <table border="0">
            <tr>
                <td class="eventCell" id="ce1">
                    <div class="eventDispl" style="display: block">
                            ${event.type.name}
                    </div>
                    <input type="text" name="eventId" value="${event.id}" style="display: none;"/>
                    <input type="text" name="eventOwnerId" value="${item.id}" style="display: none;"/>
                </td>
                <td class="eventCell" id="ce2">
                    <div class="eventDispl" style="display: block">
                            ${event.description}
                    </div>
                </td>
                <td class="eventCell" id="ce3">
                    <div class="eventDispl" style="display: block">
                            ${event.creationDate}
                    </div>
                </td>
                <td class="eventCell" id="ce4">
                    <div class="eventDispl" style="display: block">
                            ${event.status}
                    </div>
                </td>
                <td class="eventCell" id="ce5">
                    <div class="eventDispl" style="display: block">
                            ${event.support.login==null?MSG_NONE:event.support.login}
                    </div>
                </td>
                <td class="eventCell" id="ce6">
                    <img id="eventEditIcon" src="${editIconUrl}"
                         class="smallIcon" onclick="EditEvent(${customerId}, ${event.id});">
                </td>
                <c:if test="${displayManagerContext}">
                    <td class="eventCell" id="ce7">
                        <!-- TODO: L10N: pass localized confirm-question to js-function -->
                        <img src="${deleteIconUrl}" class="smallIcon"
                             onclick="DeleteEvent('${event.id}',
                                     '${item.name}',
                                     '${event.description}');">
                    </td>
                </c:if>
            </tr>
        </table>
    </form:form>
</c:forEach>

<c:if test="${currentPage eq 1}">
    <c:set var="prevDisabled" value="disabled"/>
</c:if>
<c:if test="${lastPage}">
    <c:set var="nextDisabled" value="disabled"/>
</c:if>
<div style="text-align: right;">
    <button onclick="window.location.href='${viewEvents}/${currentPage-1}'" ${prevDisabled}><-</button>
    <button onclick="window.location.href='${viewEvents}/${currentPage+1}'" ${nextDisabled}>-></button>
</div>
<br/><br/>

</body>
</html>
